import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
  'user',
  () => {
    const basicInfo = ref({})
    const setBasicInfo = (newBasicInfo) => (basicInfo.value = newBasicInfo)
    const removeBasicInfo = () => (basicInfo.value = {})

    const returnUrl = ref('/pages/index/index')
    const setReturnUrl = (url) => (returnUrl.value = url)
    const returnType = ref('switchTab')
    const setReturnType = (type) => (returnType.value = type)
    // 重置 url 和 type
    const resetReturnUrlAndType = () => {
      returnUrl.value = '/pages/index/index'
      returnType.value = 'switchTab'
    }

    return {
      basicInfo,
      setBasicInfo,
      removeBasicInfo,
      returnUrl,
      setReturnUrl,
      returnType,
      setReturnType,
      resetReturnUrlAndType,
    }
  },
  {
    persist: true,
  }
)
